package dal;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Jose Carlos Gutierrez
 */
public class ConexionOracle extends Conexion{

    private ConexionOracle(){
        Configuracion objConfiguracion =
                Configuracion.getConfiguracion();
        this.host = objConfiguracion.getDbHost();
        this.dataBase = objConfiguracion.getDbName();
        this.instance = objConfiguracion.getDbInstace();
        this.port = objConfiguracion.getDbPort();
        this.userName = objConfiguracion.getDbUser();
        this.password = objConfiguracion.getDbPassword();
    }

    public static Conexion getOrCreate(){
        if(objSingleton==null)
            objSingleton = new ConexionOracle();
        return objSingleton;
    }

    public void conectar() {Configuracion objConfiguracion =
                Configuracion.getConfiguracion();
            this.host = objConfiguracion.getDbHost();
            this.dataBase = objConfiguracion.getDbName();
            this.instance = objConfiguracion.getDbInstace();
            this.port = objConfiguracion.getDbPort();
            this.userName = objConfiguracion.getDbUser();
            this.password = objConfiguracion.getDbPassword();
        if (this.estaConectado()) {
            return;
        } else {

            try {
                Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                String sUrl = "jdbc:oracle:thin:" + this.host +":@" + this.dataBase;
                objConnection = DriverManager.getConnection(sUrl, userName, password);
            } catch (SQLException e) {
                try {
                    throw e;
                } catch (SQLException ex) {
                    ;
                }
            }
        }
    }

    public void comenzarTransaccion() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void terminarTransaccion() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void desconectar() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public ResultSet ejecutar(String query) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int ejecutarSimple(String query) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int ejecutarInsert(String query) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean estaConectado() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
